#ifndef RGB_COLOR_H
#define RGB_COLOR_H

#include <math.h>
#include "Common.h"
using namespace std;

class RGBColor
{
public:
	float r, g, b;

	RGBColor()
	{
		r = 0;
		g = 0; 
		b = 0;
	}


	RGBColor(const float color)
	{
		r = color;
		g = color;
		b = color;
	}

	RGBColor(const float& rr, const float& gg, const float& bb)
	{
		r = rr;
		g = gg;
		b = bb;
	}

	RGBColor(RGBColor& color) :r(color.r), g(color.g), b(color.b)
	{}

	RGBColor(const RGBColor& color) :r(color.r), g(color.g), b(color.b)
	{}

	static RGBColor GetBlack()
	{
		return RGBColor(0,0,0);
	}

	inline RGBColor operator + (const RGBColor &color)
	{
		return RGBColor(r + color.r, g + color.g, b + color.b);
	}

	inline RGBColor operator * (const double constant)
	{
		return RGBColor(r*constant, g * constant, b * constant);
	}

	inline RGBColor operator / (const int c)
	{
		return RGBColor(r / c, g / c, b / c);
	}

	inline RGBColor operator / (const double constant)
	{
		return RGBColor(r/ constant, g/constant, b /constant);
	}

	inline RGBColor operator / (const float constant)
	{
		return RGBColor(r / constant, g / constant, b / constant);
	}

	inline RGBColor& operator = (RGBColor color)
	{
		swap(color);
		return *this;
	}

	inline RGBColor operator * (RGBColor color)
	{
		return RGBColor(r*color.r, g * color.g, b * color.b);
	}

	inline RGBColor operator += (RGBColor currentColor)
	{
		return RGBColor(r + currentColor.r, g + currentColor.g ,b + currentColor.b);
	}

	inline RGBColor operator /= (float p_currentNumber)
	{
		return RGBColor(r /= p_currentNumber, g /= p_currentNumber, b /= p_currentNumber);
	}

	void Convert()
	{
		double newR = r / (r + 1);
		double newB = b / (b + 1);
		double newG = g / (g + 1);

		int red = newR * 256;
		int blue = newB * 256;
		int green = newG * 256;

		r = red;
		b = blue;
		g = green;

	}

	inline void swap(RGBColor& p_swapItem)
	{
		std::swap(r, p_swapItem.r);
		std::swap(g, p_swapItem.g);
		std::swap(b, p_swapItem.b);
	}


	Pixel toInt()
	{
		double newR = r / (r + 1);
		double newB = b / (b + 1);
		double newG = g / (g + 1);

		int red = newR * 256;
		int blue = newB * 256;
		int green = newG * 256;

		if (red > 255)
			red = 255;
		if (blue > 255)
			blue = 255;
		if (green > 255)
			green = 255;

		return (red << 16) + (green << 8 ) + (blue);
	}

	string ToString()
	{
		string output = "r="+to_string(r)+"-g="+to_string(g)+"-b="+to_string(b);
		return output;
	}

	static RGBColor GetColor(int colorNumber)
	{
		switch (colorNumber)
		{
		case 0:
			return RGBColor(0,0,0);
			

		case 1:
			return RGBColor(255,0,0);
			

		case 2:
			return RGBColor(0,255,0);
			

		case 3:
			return RGBColor(0, 0, 255);


		case 4:
			return RGBColor(192,192,192);

		default:
			break;
		}
	}

	inline bool operator == (int constant)
	{
		return r == constant && g == constant && b == constant;
	}

	inline bool operator == (RGBColor& p_color)
	{
		return r == p_color.r && g == p_color.g && b == p_color.b;
	}

};

inline RGBColor operator /(const RGBColor &color, const float constant)
{
	return RGBColor(color.r / constant, color.b / constant, color.g / constant);
};
//
//RGBColor operator /(const RGBColor & color, const float &constant)
//{
//	return RGBColor(color.)
//}

#endif // !RGB_COLOR_H
